package org.example.mapper;


import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.example.pojo.*;

import java.util.List;
import java.util.Map;


public interface RoleMapper {

    @Delete(" delete from role_res where r_id = #{rId}")
    int deleteRes(int rId);


    @Delete(" delete from role where r_id = #{rId}")
    int deleteRole(int rId);

    List<Role> selectRoles();

    @Select("select resource.res_id from resource where res_name=#{resName}")
    ResId selectResId(String resName);

    @Update("update role_res set roleId = #{mPassword} where r_id =#{rId}")
    int updateRole(RoleRes roleRes);


    @Insert("INSERT INTO role VALUES(null,#{rName},#{rDescription})")
    int addRole(EditRole editRole);

    @Insert("INSERT INTO role_res VALUES(#{param1},#{param2})")
    int insertRes(int rId,int resId);

    RoleRes selectRoleRes(int id);

    @Select("select * from role where r_name=#{rName}")
    Role selectByName(String rName);

    @Select("select * from resource  where res_parent_id = 0 and res_id = #{resId} ")
    ResPojo getParRes(int resId);

    @Select("select * from resource  where res_parent_id = #{resId}")
    List<ResPojo> showChildResouce(int resId);

    @Update("update role set r_name = #{rName},r_description=#{rDescription} where r_id =#{rId}")
    int updateRolePwd(Role role);

    List<Role> selectVariablesByAll(String var);

    ResRolePojo selectResRolePojo(int rId);

//    @Select("select * from manager where m_no=#{mNo} and m_password=#{mPassword}")
    User selectUserByNameAndPwd(User user);

    User selectUserByNo(String No);



    @Update("update manager set m_password = #{mPassword} where m_no =#{mNo}")
    int updateUserPwd(User user);

    @Update("update users set userAccount = userAccount - #{money} where userId = #{userId}")
    int updateUserSubMoney(Map map);

}
